package com.derbysoft.lowcostadapter.web.action.admin.hotel;

import com.derbysoft.lowcostadapter.commons.model.Status;
import com.derbysoft.lowcostadapter.commons.redis.service.HotelCacheService;
import com.derbysoft.lowcostadapter.commons.repository.HotelRepository;
import com.derbysoft.lowcostadapter.web.action.BaseAdapterAction;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by: jason
 * Date: 2012-09-28
 */
public class RefreshAction extends BaseAdapterAction {
    @Autowired
    private HotelRepository hotelRepository;

    @Autowired
    private HotelCacheService hotelCacheService;

    @Action("refreshCache")
    public void refreshCache() {
        try {
            hotelCacheService.saveAll(hotelRepository.list(Status.ENABLED));

            populateSucceededJsonResult("Refresh done !!");
        } catch (Exception ex) {
            populateSucceededJsonResult("Suffered exception !!");
        }
    }
}
